package es.us.isa.jdbl.data;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.EntityManager;

import es.us.isa.jdbl.domain.Member;
import es.us.isa.jdbl.domain.biblio.Book;
import es.us.isa.jdbl.domain.biblio.BookChapter;
import es.us.isa.jdbl.domain.biblio.Contributors;

public class ChapterDAO {
	public static List<BookChapter> getAll(EntityManager em ){
		return em.createQuery("from BookChapter").getResultList();
		
	}
	
	public static List<BookChapter> getByAuthor(EntityManager em, Member m){
		List<BookChapter> lista = em.createQuery("from BookChapter").getResultList();
		List<BookChapter> resultado = new LinkedList<BookChapter>();
		
		for (BookChapter aux:lista){
			for (Contributors c:aux.getAuthors()){
				if(c.getMemberProfile() != null){
					
					if(c.getMemberProfile().equals(m)){
						resultado.add(aux);
					}
				}
			}
		}
		return resultado;
		
		}
	
}
